package com.bite.mybatistext.mapper;

import com.bite.mybatistext.model.UserInfo;
import org.apache.catalina.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserInfoMapper {

    @Select("select * from userInfo")
    @ResultMap(value = "resultMap")
    List<UserInfo> queryAllUser();

    //起别名
    @Select("select id, username, password, age, gender, phone, " +
            "delete_flag DeleteFlag, create_time CreateTime, " +
            "update_time UpdateTime  from userInfo")
    List<UserInfo> queryAllUser1();

    //结果映射
    @Results(id = "resultMap", value = {
            @Result(column = "delete_flag", property = "deleteFlag"),
            @Result(column = "create_time", property = "createTime"),
            @Result(column = "update_time", property = "updateTime")
    })
    @Select("select * from userInfo")
    List<UserInfo> queryAllUser2();

    @Select("select * from userInfo where id = #{id}")
    List<UserInfo> getUserInfo(Integer id);

    @Select("select * from userInfo where delete_flag = #{flag} and gender = #{gender}")
    List<UserInfo> getUserInfo2(@Param("flag") Integer deleteFlag, Integer gender);

    @Insert("insert into userInfo (username, password, age, gender) " +
            "values (#{username}, #{password}, #{age}, #{gender})")
    Integer insert(UserInfo userInfo);

    @Update("update userInfo set username = #{username} where id = #{id}")
    Integer update(UserInfo userInfo);

    @Delete("delete from userInfo where id = #{id}")
    Integer delete(Integer id);
}
